﻿Imports DAO
Imports DTO
Imports System.Data.OleDb
Imports System.Data
Public Class NguoiDungDAO
    Public Function SoLuong(ByVal nd As NguoiDungDTO) As Integer
        Dim DTP As New DataProvider()
        Dim cnn As New OleDbConnection()
        cnn = DTP.ConnectDB()
        cnn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand()
        cmd.Connection = cnn
        cmd.CommandText = "select count(*) from NGUOIDUNG where User=@user "
        Dim para As OleDbParameter
        para = cmd.Parameters.Add("@user", OleDbType.VarChar)
        para.Value = nd.USER
        Dim temp As Integer
        temp = cmd.ExecuteScalar()
        Return temp
    End Function
    Public Function INSERT(ByVal ND As NguoiDungDTO) As Integer
        Try
            Dim DTP As New DataProvider()
            Dim cnn As New OleDbConnection
            cnn = DTP.ConnectDB()
            cnn.Open()
            'Dim query As String
            Dim cmd As New OleDbCommand()
            cmd.Connection = cnn
            cmd.CommandText = " Insert into NGUOIDUNG(User,Pass,HoTen,DiaChi,SoDienThoai) values (@user,@pass,@hoten,@diachi,@sodienthoai) "

            Dim para As OleDbParameter
            '
            para = cmd.Parameters.Add("@user", OleDbType.VarChar)
            para.Value = ND.USER
            '
            para = cmd.Parameters.Add("@pass", OleDbType.VarChar)
            para.Value = ND.PASS
            '
            para = cmd.Parameters.Add("@hoten", OleDbType.VarChar)
            para.Value = ND.HOTEN
            '
            para = cmd.Parameters.Add("@diachi", OleDbType.VarChar)
            para.Value = ND.DIACHI
            '
            para = cmd.Parameters.Add("@sodienthoai", OleDbType.VarChar)
            para.Value = ND.SODIENTHOAI
            '

            ' thuc thi cau truy van
            Dim temp As Integer = 0
            Try
                temp = cmd.ExecuteNonQuery()
            Catch ex As Exception
                ex.Message.ToString()
            End Try

            cnn.Close()
            If (temp > 0) Then
                Return 1
            Else
                Return 0
            End If
        Catch ex As Exception
            ex.Message.ToString()
        End Try
        
    End Function
End Class
